package flex.lms.service;

import java.sql.Date;
import java.util.List;

import javax.annotation.Resource;

import org.common.db.query.HQLQuery;
import org.grizzly.service.BaseService;
import org.springframework.stereotype.Service;

import com.sun.org.apache.bcel.internal.generic.NEW;

import flex.lms.entity.StuExperGrade;
import flex.lms.entity.User;

@Service
public class ChengJiGuanLiService {
	
	@Resource
	private BaseService baseService;
	
	public List<User> getUserNameList(){
		
		String hql = "from User u where u.userType=1";
		List<User> userInfoList =  baseService.findObjects(new HQLQuery(hql));
		return userInfoList;
	}
	
	public List<StuExperGrade> getChengJiByBianHao(StuExperGrade stuExperGrade){
		String hql = "from StuExperGrade g where g.userName = '"+stuExperGrade.getUserName()+"'";
		List<StuExperGrade> stuExperGradeList = baseService.findObjects(new HQLQuery(hql));
		return stuExperGradeList;
	}
	
	public List<StuExperGrade> getChengjiByRiQi(StuExperGrade stuExperGrade){
		String hql = "from StuExperGrade g where g.examTime like '%"+stuExperGrade.getExamTime()+"%'";
		List<StuExperGrade> stuExperGradeList = baseService.findObjects(new HQLQuery(hql));
		return stuExperGradeList;
	}
	
	
	public void updateChengJiByBianHao(StuExperGrade stuExperGrade) throws Exception{		
		String hql = "update StuExperGrade set grade = '"+stuExperGrade.getGrade()+"' where id='"+stuExperGrade.getId()+"'";
		baseService.update(new HQLQuery(hql));
	}

	public String getUserName(String userName) {
		String hql = "from User u where u.userName='"+userName+"'";
		List<User> userInfoList =  baseService.findObjects(new HQLQuery(hql));		
		return userInfoList.get(0).getName();
	}

}
